package info.wangyuan.agent.controller.admin;

import info.wangyuan.agent.entity.po.AgentConfig;
import info.wangyuan.agent.service.curd.impl.AgentConfigService;
import info.wangyuan.agent.utils.Result;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理员智能体管理
 *
 * @author Albert
 * @since 2025-07-14 02:33:07
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/admin/agent")
public class AgentController {

    private final AgentConfigService agentConfigService;

    public AgentController(AgentConfigService agentConfigService) {
        this.agentConfigService = agentConfigService;
    }

    /**
     * 获取智能体列表
     */
    @GetMapping("/list")
    public Result<List<AgentConfig>> getAgentList() {
        return Result.success(agentConfigService.list());
    }

    /**
     * 获取单个智能体配置信息
     */
    @GetMapping("/{agentId}")
    public Result<AgentConfig> getModelInfo(@PathVariable Integer agentId) {
        return Result.success(agentConfigService.getById(agentId));
    }

    /**
     * 智能体添加
     */
    @PostMapping("/add")
    public Result<Void> addAgent(@RequestBody @Valid AgentConfig agentConfig) {
        agentConfigService.canAdd(agentConfig);
        return Result.success();
    }

    /**
     * 智能体修改（包含配置修改和状态激活）
     * 必须传id、status字段
     */
    @PostMapping("/update")
    public Result<Void> updateAgent(@RequestBody @Valid AgentConfig agentConfig) {
        agentConfigService.canUpdate(agentConfig);
        return Result.success();
    }

    /**
     * 智能体删除
     */
    @DeleteMapping("/delete/{id}")
    public Result<Void> deleteAgent(@PathVariable @NotNull Integer id) {
        agentConfigService.canDelete(id);
        return Result.success();
    }
}
